<template>
  <div class="goods-container">
    <van-list
      v-model="loading"
      :finished="finished"
      finished-text="没有更多了"
      @load="onLoad"
    >
    <div class="list">
      <div v-for="item in productList" :key="item.id" class="list-col">
        <div class="list-item" @click="$router.push({path: '/product', query: {productId: item.id}})">
          <div class="goods-item-photo">
            <van-image :src="item.coverImg"></van-image>
          </div>
          <div class="list-item-info">
            <div class="list-item-title">
              {{ item.name }}
            </div>
            <div class="list-item-price">
              <div class="price">
                <span class="price-symbol">&#165;</span>
                <span class="price-integer">{{ item.price }}</span>
                
              </div>
            </div>
          </div>
        </div>
        
      </div>
    </div>
      <!-- <div class="goods-item" v-for="(item, index) in productList" :key="index">
        <van-image :src="item.url"  v-lazy="item.url  "/>
      </div> -->
    </van-list>
    
  </div>
</template>

<script>

import { getRecommendProduct } from '@/api/product'

export default {
  name: 'GoodsList',
  data() {
    return {
      loading: false,
      finished: false,
      productList: [],
    }
  },
  mounted() {
  },
  
  methods: {
    onLoad() {
      getRecommendProduct({pageNum: this.pageNum, pageSize: this.pageSize}).then(res => {
        if(res.code === 200) {
          this.loading = false;
          this.productList = this.productList.concat(res.data.records);
          if(res.data.records.page == res.data.pageNum  || res.data.records.length == 0) {
            this.finished = true;
          } else {
            this.finished = false;
          }
        }
      })
    }
  }

}
</script>

<style lang="scss" scoped>
  .goods-container {
    padding-top: 20px;
    position: relative;
    .list {
      display: flex;
      flex-wrap: wrap;
      padding-left: 6.4px;
      padding-right: 6.4px;
      .list-col {
        width: 50%;
        box-sizing: border-box;
        padding-left: 6.4px;
        padding-right: 6.4px;
        margin-bottom: 12.8px;
        .list-item {
          position: relative;
          text-align: left;
          overflow: hidden;
          background: #fff;
          border-radius: 10.24px;
          .list-item-info {
            padding: 10px;
            .list-item-title {
              font-size: 16px;
              color: #333333;
              min-height: 46.08px;
              line-height: 23.04px;
              display: -webkit-box;
              overflow: hidden;
              text-overflow: ellipsis;
              -webkit-line-clamp: 2;
              -webkit-box-orient: vertical;
            }
            .list-item-price {
              .price {
                color: #ff4142;
                .price-symbol {
                  font-size: 12px;
                  margin-right: 3px;
                }
                .price-integer {
                  font-size: 21px;
                }
              }
            }
          }
        }
      }
    }
  }
</style>